package Engine;

//
//  TheParser.java
//  Engine
//
//  Created by Jeremy W on 6/8/10.
//  Copyright 2010 Jeremy Walker. All rights reserved.
//

import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import Engine.util.JdbcConnection;

public class TheParser {

	public static void main(String args[]) {
		
		// File file = new File("/doc.xml");
		try {
			
			Connection conn = new JdbcConnection().getConnection();
			if (args[0].equals("guild")) {
			Guilds guild = new Guilds();
			guild.refreshGuilds(conn);
			guild.updateGuilds(conn);
			guild = null;
			} else if ( args[0].equals("char")) {
			
			Character toon = new Character();
			toon.refreshCharacters(conn);
			toon = null;
			} else {
				Guilds guild;
				Character toon;
				for(int i =0; i<9; i++) {		
					System.gc();
					try {
						guild = new Guilds();
 	                			guild.refreshGuilds(conn);
        	        			guild.updateGuilds(conn);
               					guild = null;
					System.gc();
					} catch (Exception sqle) {
						//ignore;
					}

					try {
						toon = new Character();
                        			toon.refreshCharacters(conn);
                        			toon = null;
					System.gc();
					} catch (Exception sqle) {
						//ignore
					}
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
